package com.fuhao.member.mapper;

import com.fuhao.member.entity.MemberTokenEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserTokenMapper {

	/**
	 * userid+登录类型+可用查询用户信息
	 * @param userId
	 * @param loginType
	 * @return
	 */
	@Select("SELECT id as id ,token as token ,login_type as LoginType, device_infor as deviceInfor ,is_availability as isAvailability,user_id as userId"
			+ "" + ""
			+ " , create_time as createTime,update_time as updateTime   FROM mail_user_token WHERE user_id=#{userId} AND login_type=#{loginType} and is_availability='0'; ")
	MemberTokenEntity selectByUserIdAndLoginType(@Param("userId") Long userId, @Param("loginType") String loginType);

	/**
	 * 更新用户不可用
	 * @param userId
	 * @param loginType
	 * @return
	 */
	@Update("    update mail_user_token set is_availability ='1',update_time=now()   where user_id=#{userId} and login_type =#{loginType} ")
	int updateTokenAvailability(@Param("userId") Long userId, @Param("loginType") String loginType);

	/**
	 * 根据token更新为不可用状态
	 * @param token
	 * @return
	 */
	@Update(" update mail_user_token set is_availability ='1',update_time=now() where token=#{token}")
    int updateAvailabilityByToken(@Param("token") String token);
	/**
	 * 插入token信息
	 * @param memberTokenEntity
	 * @return
	 */
	@Insert("    INSERT INTO `mail_user_token` VALUES (null, #{token},#{loginType}, #{deviceInfor}, 0, #{userId} ,now(),null ); ")
	int insertUserToken(MemberTokenEntity memberTokenEntity);
}
